﻿using AnQinManagermentBackendAPI.Model.DTO.DevelopManagement;
using AnQinManagermentBackendAPI.Model.View.DevelopManagement;
using AnQinManagermentBackendAPI.Service;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;

namespace AnQinManagermentBackendAPI.Controller
{
    /// <summary>
    /// 开发管理表
    /// </summary>
    [Route("api/[controller]")]
    [ApiController]
    [Authorize]
    public class DevelopManagementController : ControllerBase
    {
        /**
         * 开发管理业务接口
         */
        private readonly DevelopManagementService _developManagementService;

        /**
         * 构造函数注入
         */
        public DevelopManagementController(DevelopManagementService developManagementService)
        {
            _developManagementService = developManagementService;
        }

        /// <summary>
        /// 获取开发管理列表
        /// </summary>
        /// <param name="developManagementSearchDTO"></param>
        [HttpGet]
        [ProducesResponseType(typeof(DevelopManagementView), 200)]
        public async Task<IActionResult> GetDevelopManagementList([FromQuery] DevelopManagementSearchDTO developManagementSearchDTO)
        {
            var response = await _developManagementService.GetDevelopManagementList(developManagementSearchDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 新增开发管理
        /// </summary>
        /// <param name="developManagementAddDTO"></param>
        [HttpPost]
        public async Task<IActionResult> AddDevelopManagement([FromBody] DevelopManagementAddDTO developManagementAddDTO)
        {
            var response = await _developManagementService.AddDevelopManagement(developManagementAddDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更新开发管理
        /// </summary>
        /// <param name="developManagementUpdateDTO"></param>
        [HttpPut]
        public async Task<IActionResult> PutDevelopManagement([FromBody] DevelopManagementUpdateDTO developManagementUpdateDTO)
        {
            var response = await _developManagementService.PutDevelopManagement(developManagementUpdateDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 删除开发管理
        /// </summary>
        [HttpDelete]
        public async Task<IActionResult> DeleteDevelopManagement([FromQuery] string Id)
        {
            var response = await _developManagementService.DeleteDevelopManagement(Id);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 开发开始
        /// </summary>
        [HttpPost("Start")]
        public async Task<IActionResult> StartDevelopManagement([FromBody] DevelopManagementPlanDTO developManagementPlanDTO)
        {
            var response = await _developManagementService.StartDevelopManagement(developManagementPlanDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 更改计划时间
        /// </summary>
        [HttpPut("UpdatePlanTime")]
        public async Task<IActionResult> UpdatePlanTimeDevelopManagement([FromBody] DevelopManagementPlanDTO developManagementPlanDTO)
        {
            var response = await _developManagementService.UpdatePlanTimeDevelopManagement(developManagementPlanDTO);
            return StatusCode(response.Status, response);
        }

        /// <summary>
        /// 开发完成
        /// </summary>
        [HttpPost("Finish")]
        public async Task<IActionResult> FinishDevelopManagement([FromBody] string Id)
        {
            var response = await _developManagementService.FinishDevelopManagement(Id);
            return StatusCode(response.Status, response);
        }
    }
}
